hw2
Box.h
#ifndef Box_H
#define Box_H
#include <string>
using namespace std;
class Box
{
public:
Box();
Box(double , double , double , string);
double Volume();
bool CompareVolume(Box &);
string getName();
private:
double length, breadth, height;
string _name;
};
#endif
Box.cpp
#include <iostream>
#include <string>
#include "Box.h"
using namespace std;
Box::Box()
{
length = 0;
breadth = 0;
height = 0;
_name = "";
cout << "Box constructor called";
}
Box::Box(double L, double B, double H, string N)
{
length = L;
breadth = B;
height = H;
_name = N;
cout << "Box constructor called" << endl;
}
double Box::Volume()
{
return length*breadth*height;
}
bool Box::CompareVolume(Box &CompareBox)
{
if (this->Volume() > CompareBox.Volume())
return 1;
else
return 0;
}
string Box::getName()
{
return this->_name;
}
main.cpp
#include <iostream>
#include <string>
#include "Box.h"
using namespace std;
int main()
{
Box firstBox(19.0, 11.0, 5.0, "First Box");
Box secondBox(17.0, 10.0, 8.0, "second Box");
cout << "Volume of first Box = " << firstBox.Volume() << endl;
cout << "Volume of second Box = " << secondBox.Volume() << endl;
cout << firstBox.getName()
<< " is "
<< (firstBox.CompareVolume(secondBox) == 1 ? "" : "not ")
<< "greater than the "
<< secondBox.getName();
system("pause");
return 0;
}